<?
if (!defined('MODULE_FILE')){
die ("cant access file directly!");
}

$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );

autoLoader();

$objBaseAppointments 	= new BaseAppointments();
$objAppointments 		= new Appointments();
$objDoctors 	= new Doctors();

?>
<html>
<head>
<?php require_once 'commonJS.php'; ?>
  <script type="text/javascript" src="js/jquery.timepicker.js"></script>
  <link rel="stylesheet" type="text/css" href="css/jquery.timepicker.css" />
<script>
	$(function() {
		$('#basicExample').timepicker();
	});
</script>
<script>
    $(document).ready(function(){
                   $( "#from" ).datepicker({
                        dateFormat: 'yy-mm-dd',
                        showOn: "button",
			buttonImage: "images/calendar.gif",
			buttonImageOnly: true,
                        changeMonth: true,
                        changeYear: true,
                        yearRange: "-30"
                   });
              });
</script>
	<script type="text/javascript">
    $('#doctor_id').change(function(){
               var doctor_id1 = $('#doctor_id').val();
                  $.ajax({
                     type: "POST",
                     url: "modules.php?file=getdoctor_details&type=search&doctorid=" + doctor_id1,
                     data:{doctorid:doctor_id1 ,type:'salaryDelete'},
                     beforeSend : function () {
                        //$('#wait').html("Wait for checking");
                     },
                     success:function(returnData){
						strCustomerData = returnData;
						var strData = strCustomerData.split( '_' );
					    $('#docdetails').html(strData[0]);
                     }
                  });
               
            });
			
</script>
</head>
<body>
	<br>
	<div class="col-lg-10">
		<div class="panel panel-primary">
			<div class="panel-heading">
				<i class="fa fa-bell fa-fw"></i>Take an Appointment
			</div>
			<div class="panel-body">
	<form METHOD="POST" action="modules.php?file=insert_department&type=insert&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>" id="formSubmit" name="formSubmit" >
		<table width="100%" cellspacing="0" cellpadding="3">
		<?php
				$intAppoinmentId = NULL;
				$intPatientId 	= NULL;
				$intDoctorId 	= NULL;
				$intParantDepartmentId = NULL;
				$strDepartmentHeadName = NULL;
				$intDepartmentHeadId = NULL;
				$strOfficeNumber = NULL;
				$intEmployeeCount = NULL;
				$strAddress = NULL;
				$strContactPerson = NULL;
				
				if( true == isset( $_GET['appoinment_id'] ) && true == valStr( $_GET['appoinment_id'] ) ) {
					$intAppoinmentId = $_GET['appoinment_id'];
					
					$objDepartment = $objAppointments->fetchAppointmentsById( $_GET['appoinment_id'] );
					
					if( true == valObj( $objDepartment, 'BaseDepartments' ) ) {
						$strName 				= $objDepartment->getName();
						$strDescription 		= $objDepartment->getDescription();
						$intParantDepartmentId 	= $objDepartment->getParantDepartmentId();
						$strDepartmentHeadName 	= $objDepartment->getDepartmentHeadName();
						$intDepartmentHeadId 	= $objDepartment->getDepartmentHeadId();
						$strOfficeNumber 		= $objDepartment->getOfficeNumber();
						$intEmployeeCount 		= $objDepartment->getEmployeeCount();
						$strAddress 		    = $objDepartment->getAddress();
						$strContactPerson 		= $objDepartment->getContactPerson();
					}
				} else if( true == valObj( $objDepartment, 'BaseDepartments' ) ) {
					$intAppoinmentId = $objDepartment->fetchNextId();
				}
				?>	
						<tr><td height="10" colspan="4"><input id="appoinment_id" Name="appoinment_id" type="hidden"  style="width:100px;"  value="<?php echo $intAppoinmentId;?>"></td></tr>
						<tr valign="top">
							<td width="130">Doctor Name</td>
							<td>
							<select class="validate[required]" name="doctor_id"
								id="doctor_id" style="width: 202px;">
							    <option value=''>-Select-</option>
								<?php
								$arrobjDoctors = $objDoctors->fetchAllDoctors();
								
								if( true == valStr( $arrobjDoctors ) ) {
									foreach( $arrobjDoctors as $Doctor ) {
										echo '<option' . ( ( $intDoctorId == $Doctor->getId() ) ? ' selected' : '' ) . ' value=' . $Doctor->getId() . '>' . $Doctor->getFirstName() . '&nbsp;'. $Doctor->getLastName(). '</option>';
									}
								}
							?>	
							</select>
							</td>
							<td width="130">Patient Name</td>
							<td>
								<input id="patient_id" Name="patient_id" type="text" class="validate[required]" style="width: 240px;">
							</td>
							
							
						</tr>
						<tr>
							<td colspan="4" height="10px"></td>
						</tr>
						<tr valign="top">

							<td width="130">Date</td>
							<td><input class="validate[required]" readonly type="text" name="from" id="from" value="" style="width:202px;"></td>
							<td width="130">Time</td>
							<td><input id="basicExample" type="text" class="validate[required]" style="width:202px;" class="time" /></td>
							
						</tr>
						<tr>
							<td colspan="4" height="10px"></td>
						</tr>
						<tr valign="top">
						<td  width="130">Mobile Number</td>
						<td><input id="mobile_number" Name="mobile_number" type="text" class="" style="width:202px;" value="<?php echo $strMobileNumber; ?>"></td>
						<td  width="130">Gender</td>
							<td>
								<select class="validate[required]" name="gender" id="gender" style="width:202px;">
									<option value=''>-Select-</option>
									<option value='1' <?php echo ( ( 1 == $strGender ) ? 'selected' : '' ); ?>>Male</option>
									<option value='2' <?php echo ( ( 2 == $strGender ) ? 'selected' : '' ); ?>>Female</option>
									<option value='3' <?php echo ( ( 3 == $strGender ) ? 'selected' : '' ); ?>>Other</option>
								</select>
							</td>
						</tr>
						<tr>
							<td colspan="4" height="20px"></td>
						</tr>
						<tr>
						<td width="130">Note</td>
						<td colspan="3" ><textarea name="note" rows="4" cols="40"></textarea></td>
						</tr>
						<tr><td colspan="4" height="20px"></td></tr>
						<tr valign="top">
							<td class="mandatory" width="130">&nbsp;</td>
							<td colspan="3">
							<?php
								if( true == isset( $_GET['patient_id'] ) && true == valStr( $_GET['patient_id'] ) ) {
									echo "<input type=hidden name=operation value=update>";
									echo "<input type=submit value=UPDATE id=Submit name=Submit>";
								} else {
									echo "<input type=hidden name=operation value=insert>";
									echo "<input type=submit value=SUBMIT id=Submit name=Submit>";
								}
							?>
							<a href="modules.php?file=view_patients&type=view&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>"><input type="button" name="calcle" value="Cancel" /></a>
						</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>
	<div id="docdetails"></div>
</body>
</html>
